package com.flexcodejam.vfd.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;	
	
	import com.flexcodejam.vfd.business.*;
	import com.flexcodejam.vfd.control.*;
	import com.flexcodejam.vfd.event.*;	
	import com.flexcodejam.vfd.model.*;
	import com.flexcodejam.vfd.vo.*;			
	
	import mx.rpc.IResponder;
	import mx.rpc.events.*;
	import mx.controls.Alert;
	import mx.utils.ObjectUtil;
	import flash.events.Event;
	
	public class SaveUserCommand  implements ICommand, IResponder
	{
	private var model:VFDModelLocator = VFDModelLocator.getInstance();
		
		public function SaveUserCommand():void
		{
			//  constructor...
		}
			
		public function execute(event:CairngormEvent):void
		{	
			//Todo Call Command
	
			var delegate:UserDelegate = new UserDelegate (this);					
			var userEvent:UserEvent = event as UserEvent;
			var user:User = (event as UserEvent).user
	
			// Alert.show(ObjectUtil.toString(user));
			delegate.SaveUser(user);			 	
		}
		
		
		public function result(event:Object):void
		{
			// set the current user
			model.currentUser = event.result;
		
			var ev:ChangeMainViewStackEvent = new ChangeMainViewStackEvent(ChangeMainViewStackEvent.GO_TO_THANK_YOU,true,false);
			CairngormEventDispatcher.getInstance().dispatchEvent(ev);				
		}
		
		public function fault(event:Object):void
		{
			// display the error message to the user 
			Alert.show(ObjectUtil.toString(event.toString()).substring(1,600), "Error");
		}

	}

 	
}	
	
